package ui

import applicationModel.BuscadorZombie
import dominio.Zombie
import java.awt.Color
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.TextBox
import org.uqbar.arena.widgets.tables.Column
import org.uqbar.arena.widgets.tables.Table
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.WindowOwner

class AlmanaqueZombieWindow extends Dialog<BuscadorZombie> {

	new(WindowOwner parent, BuscadorZombie buscador) {
		super(parent, buscador)
		modelObject.search()
	}

	override def createMainTemplate(Panel mainPanel) {
		title = "Almanaque de Zombies"

		super.createMainTemplate(mainPanel)

		this.createResultsGrid(mainPanel)
		this.createGridActions(mainPanel)
	}

	override protected createFormPanel(Panel mainPanel) {
		var searchFormPanel = new Panel(mainPanel)
		searchFormPanel.setLayout(new ColumnLayout(2))

		var labelNumero = new Label(searchFormPanel)
		labelNumero.text = "Nombre de Zombi"
		labelNumero.foreground = Color::RED

		new TextBox(searchFormPanel).bindValueToProperty("nombre")
	}

	override protected addActions(Panel actionsPanel) {
		new Button(actionsPanel).setCaption("Buscar").onClick[|modelObject.search].setAsDefault.disableOnError

		new Button(actionsPanel).setCaption("Limpiar").onClick[|modelObject.clear]
	}

	def protected createResultsGrid(Panel mainPanel) {
		var table = new Table<Zombie>(mainPanel, typeof(Zombie))
		table.heigth = 200
		table.width = 450
		table.bindItemsToProperty("resultados")
		this.describeResultsGrid(table)
	}

	def void describeResultsGrid(Table<Zombie> table) {
		new Column<Zombie>(table) //
		.setTitle("Nombre").setFixedSize(150).bindContentsToProperty("nombre")

		new Column<Zombie>(table).setTitle("Potencia").setFixedSize(50).bindContentsToProperty("potencia")

		new Column<Zombie>(table).setTitle("Descripcion").setFixedSize(100).bindContentsToProperty("descripcion")
	}

	//override protected addActions(Panel actionsPanel) {
	//val botonvolver = new Button(actionsPanel).setAsDefault.setCaption("Tablero")
	//botonvolver.onClick[|cancel]
	//}
	def createGridActions(Panel mainPanel) {
		var actionsPanel = new Panel(mainPanel)
		actionsPanel.setLayout(new HorizontalLayout)
		val botonvolver = new Button(actionsPanel).setAsDefault.setCaption("Tablero")
		botonvolver.onClick[|cancel]
	}
}
